#include <iostream>
#include <vector>
using namespace std;

int max_cost_recur(vector<int> &v, vector<int> &w, vector<int> &s, int n, int m)
{
        if(n == 0){
                return 0;
        }

        int max_cost = max_cost_recur(v, w, s, n - 1, m);
        for(int i = 1; i <= s[n] && m >= v[n] * i; i++){
                max_cost = max(max_cost, max_cost_recur(v, w, s, n - 1, m - v[n] * i) + w[n] * i);
        }

        return max_cost;
}

int max_cost_recur(vector<int> &v, vector<int> &w, vector<int> &s, int n, int m, vector<vector<int>> &recd)
{
        if(n == 0){
                return 0;
        }

        if(recd[n][m] != -1){
                return recd[n][m];
        }

        int max_cost = max_cost_recur(v, w, s, n - 1, m, recd);
        for(int i = 1; i <= s[n] && m >= v[n] * i; i++){
                max_cost = max(max_cost, max_cost_recur(v, w, s, n - 1, m - v[n] * i, recd) + w[n] * i);
        }

        return recd[n][m] = max_cost;
}

int max_cost_dp(vector<int> &v, vector<int> &w, vector<int> &s, int n, int m)
{
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= m; j++){
                        dp[i][j] = dp[i - 1][j];
                        for(int k = 1; k <= s[i] && j >= k * v[i]; k++){
                                dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i] * k] + w[i] * k);
                        }
                }
        }
        return dp.back().back();
}

int main()
{
        int n, m;
        cin>>n>>m;
        vector<int> v(n + 1, 0), s(v), w(v);

        for(int i = 1; i <= n; i++){
                cin>>v[i]>>w[i]>>s[i];
        }

        vector<vector<int>> recd(n + 1, vector<int>(m + 1, -1));
        //cout<<max_cost_recur(v, w, s, n, m, recd)<<endl;
        cout<<max_cost_dp(v, w, s, n, m)<<endl;
        return 0;
}